package com.foxzzz.two.pointers;

public class Solution283 {

    public void moveZeroes(int[] nums) {
        if (nums.length < 2) {
            return;
        }
        int j = 0;
        for (int i = 0; i < nums.length; i++) {
            while (nums[j] != 0) {
                j++;
                if (j == nums.length) {
                    return;
                }
            }
            while (nums[i] == 0 || i < j) {
                i++;
                if (i == nums.length) {
                    return;
                }
            }
            nums[j] = nums[i];
            nums[i] = 0;
        }
    }

    public static void main(String[] args) {

        new Solution283().moveZeroes(new int[]{0,1});
        new Solution283().moveZeroes(new int[]{0,1,0,3,12});
    }
}
